package com.neuedu.amqp.consumer.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DirectConfig {
    /**
     * ● 声明交换机
     * ● @return Direct 类型交换机
     */
    @Bean
    public DirectExchange directExchange() {
        return ExchangeBuilder.directExchange("yyzx.direct1").build();
    }

    /**
     * ● 第一个队列
     */
    @Bean
    public Queue directQueue1() {
        return new Queue("direct1.queue1");
    }

    /**
     * ● 绑定队列和交换机
     * ● @param directQueue1 ： 队列
     * ● @param directExchange ：交换机
     * ● 需要设置 routingKey :red
     */
    @Bean
    public Binding bindingQueue1WithRed(Queue directQueue1, DirectExchange directExchange) {
        return BindingBuilder.bind(directQueue1).to(directExchange).with("red");
    }

    /**
     * ● 绑定队列和交换机
     * ● @param directQueue1 ： 队列
     * ● @param directExchange ：交换机
     * ● 需要设置 routingKey :blue
     */
    @Bean
    public Binding bindingQueue1WithBlue(Queue directQueue1, DirectExchange directExchange) {
        return BindingBuilder.bind(directQueue1).to(directExchange).with("blue");
    }

    /**
     * ● 第二个队列
     */
    @Bean
    public Queue directQueue2() {
        return new Queue("direct1.queue2");
    }

    /**
     * ● 绑定队列和交换机
     * ● @param directQueue2 ： 队列
     * ● @param directExchange ：交换机
     * ● 需要设置 routingKey :red
     */
    @Bean
    public Binding bindingQueue2WithRed(Queue directQueue2, DirectExchange directExchange) {
        return BindingBuilder.bind(directQueue2).to(directExchange).with("red");
    }

    /**
     * ● 绑定队列和交换机
     * ● @param directQueue2 ： 队列
     * ● @param directExchange ：交换机
     * ● 需要设置 routingKey :yellow
     */
    @Bean
    public Binding bindingQueue1WithYellow(Queue directQueue2, DirectExchange directExchange) {
        return BindingBuilder.bind(directQueue2).to(directExchange).with("yellow");
    }
}
